package com.luocj.elephant.demo.activity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

import com.luocj.elephant.demo.R;
import com.luocj.elephant.demo.utils.Utils;
import com.luocj.elephant.demo.view.MyPieView;
import com.luocj.elephant.demo.view.MyRingView;
import com.luocj.elephant.demo.view.RingView;

public class RingViewActivity extends AppCompatActivity {

    private int progress = 0;

    private String TAG = RingViewActivity.class.getSimpleName();
    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    if (progress < 100) {
                        progress++;
                        myringview.setProgress(progress);

                    }
                    break;

            }
        }
    };
    private RingView progressbar;
    private MyRingView myringview;
    private MyPieView pieview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ring_view);
        WindowManager manager = this.getWindowManager();
        DisplayMetrics outMetrics = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(outMetrics);
        int width = outMetrics.widthPixels;
        int height = outMetrics.heightPixels;

        Log.i(TAG, "onCreate: " + width + "============>" + height);
        initView();



    }

    private void initView() {
        progressbar = (RingView) findViewById(R.id.progress_bar_2);
        progressbar.setRingWidth(5);
        progressbar.setRingColor(Color.RED);
        progressbar.setRingProgressColor(Color.YELLOW);
        progressbar.setMax(100);
        progressbar.setResult(400);
        progressbar.setProgress(50);

        myringview = findViewById(R.id.myringview);
        pieview = findViewById(R.id.mypieview);

    }

    public void start(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        Thread.sleep(100);
                        mHandler.sendEmptyMessage(0);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }).start();
    }
}
